package com.sharing.controller;

import com.sharing.common.Result;
import com.sharing.domain.UserTalk;
import com.sharing.service.UserTalkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/talk")
public class UserTalkController {
    @Autowired
    private UserTalkService userTalkService;

    /**
     * 根据发送用户id和接收用户id查询两个用户之间days天内的对话记录（按照时间从早到晚展示）
     * @param senderId
     * @param acceptorId
     * @param days
     * @return
     */
    @GetMapping
    public Result<List<UserTalk>> selectUserTalksBySenderIdAndAcceptorId(Integer senderId, Integer acceptorId, Integer days) {
        return userTalkService.selectUserTalksBySenderIdAndAcceptorId(senderId, acceptorId, days);
    }

    /**
     * 通过两个用户id查询他们之间对话记录
     * @param ids
     * @param days
     * @return
     */
    @GetMapping("/all")
    public Result<List<UserTalk>> selectUserTalksByIds(@RequestParam List<Integer> ids, Integer days) {
        return userTalkService.selectUserTalksByIds(ids, days);
    }

    /**
     * 新增对话
     * @param userTalk
     * @return
     */
    @PostMapping
    public Result<UserTalk> insertUserTalk(@RequestBody UserTalk userTalk) {
        return userTalkService.insertUserTalk(userTalk);
    }

    /**
     * 删除对话
     * @param id
     * @return
     */
    @DeleteMapping
    public Result<Integer> deleteUserTalkById(Integer id) {
        return userTalkService.deleteUserTalkById(id);
    }
}
